package main

import (
	"fmt"
	"io"
	"os"
)

func main() {
	srcFile := "doc/hello.txt"
	destFile := "doc/hello_dest.txt"

	src, e := os.Open(srcFile)	//打开文件
	if e != nil {
		fmt.Println("open file occur error.", e)
		return
	}
	defer src.Close()	//关闭文件

	dest, e := os.Create(destFile)	//创建目标文件
	if e != nil {
		fmt.Println("create file occur error", e)
		return
	}
	defer dest.Close()	//关闭文件

	_, e = io.Copy(dest, src)
	if e != nil {
		fmt.Println("copy file failed.", e)
	} else {
		fmt.Println("copy file success.")
	}

}
